/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FormBukuPiutang.java
 *
 * Created on May 22, 2011, 12:11:25 AM
 */

package com.kifas.ui.finance;

import com.kifas.model.xml.BukuPiutangModel;
import com.kifas.model.xml.CustomerModel;
import com.kifas.model.xml.PiutangModel;
import com.kifas.service.MainService;
import java.awt.Component;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.AbstractTableModel;
import org.jdesktop.beansbinding.AutoBinding.UpdateStrategy;
import org.jdesktop.beansbinding.BindingGroup;
import org.jdesktop.swingbinding.JComboBoxBinding;
import org.jdesktop.swingbinding.SwingBindings;

/**
 *
 * @author dhamarsu
 */
public class FormBukuPiutang extends javax.swing.JInternalFrame {
    private List<CustomerModel> customers;
    private List<PiutangModel> piutangModels;
    private List<BukuPiutangModel> bukuPiutangModels;
    private PiutangModel piutangModel;
    
    /** Creates new form FormBukuPiutang */
    public FormBukuPiutang() {
        initComponents();

        customers = MainService.getMasterService().getCustomers();

        BindingGroup bindingGroup = new BindingGroup();
        JComboBoxBinding custBinding =
                SwingBindings.createJComboBoxBinding(
                UpdateStrategy.READ,
                customers,
                cboCustomer);

        cboCustomer.setRenderer(new DefaultListCellRenderer() {
           @Override
           public Component getListCellRendererComponent(
                   JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
               super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
               if (value instanceof CustomerModel) {
                   CustomerModel mec = (CustomerModel)value;
                   setText(mec.getNama());
               }
               return this;
           }
        });

        bindingGroup.addBinding(custBinding);
        bindingGroup.bind();

        piutangModels = new ArrayList<PiutangModel>();
        bukuPiutangModels = new ArrayList<BukuPiutangModel>();
        tbPiutang.getSelectionModel().addListSelectionListener(new PiutangSelectionListener());
        refreshTablePiutang();

        dtTgl1.setDate(new Date());
        dtTgl2.setDate(new Date());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jToolBar1 = new javax.swing.JToolBar();
        btnAddPiutang = new javax.swing.JButton();
        btnPenerimaan = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        dtTgl1 = new com.toedter.calendar.JDateChooser();
        jLabel2 = new javax.swing.JLabel();
        dtTgl2 = new com.toedter.calendar.JDateChooser();
        jLabel3 = new javax.swing.JLabel();
        cboCustomer = new javax.swing.JComboBox();
        rdoJthTempo = new javax.swing.JRadioButton();
        rdoBlmLunas = new javax.swing.JRadioButton();
        rdoLunas = new javax.swing.JRadioButton();
        rdoAll = new javax.swing.JRadioButton();
        btnFilter = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbPiutang = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        tbBukuPiutang = new javax.swing.JTable();

        setClosable(true);
        setIconifiable(true);
        setTitle("Form Buku Piutang");

        jToolBar1.setRollover(true);
        jToolBar1.setName("jToolBar1"); // NOI18N
        jToolBar1.setPreferredSize(new java.awt.Dimension(512, 75));

        btnAddPiutang.setText("Add Piutang");
        btnAddPiutang.setFocusable(false);
        btnAddPiutang.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnAddPiutang.setName("btnAddPiutang"); // NOI18N
        btnAddPiutang.setPreferredSize(new java.awt.Dimension(100, 37));
        btnAddPiutang.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnAddPiutang.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddPiutangActionPerformed(evt);
            }
        });
        jToolBar1.add(btnAddPiutang);

        btnPenerimaan.setText("Pembayaran ");
        btnPenerimaan.setName("btnPenerimaan"); // NOI18N
        btnPenerimaan.setPreferredSize(new java.awt.Dimension(100, 37));
        btnPenerimaan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPenerimaanActionPerformed(evt);
            }
        });
        jToolBar1.add(btnPenerimaan);

        jButton3.setText("Print");
        jButton3.setName("jButton3"); // NOI18N
        jButton3.setPreferredSize(new java.awt.Dimension(100, 37));
        jToolBar1.add(jButton3);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Filter"));
        jPanel1.setName("jPanel1"); // NOI18N

        jLabel1.setText("Tanggal");
        jLabel1.setName("jLabel1"); // NOI18N

        dtTgl1.setDateFormatString("dd/MM/yyyy");
        dtTgl1.setName("dtTgl1"); // NOI18N

        jLabel2.setText("s/d");
        jLabel2.setName("jLabel2"); // NOI18N

        dtTgl2.setDateFormatString("dd/MM/yyyy");
        dtTgl2.setName("dtTgl2"); // NOI18N

        jLabel3.setText("Customer");
        jLabel3.setName("jLabel3"); // NOI18N

        cboCustomer.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cboCustomer.setName("cboCustomer"); // NOI18N
        cboCustomer.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cboCustomerItemStateChanged(evt);
            }
        });

        buttonGroup1.add(rdoJthTempo);
        rdoJthTempo.setText("Piutang Jth Tempo");
        rdoJthTempo.setName("rdoJthTempo"); // NOI18N

        buttonGroup1.add(rdoBlmLunas);
        rdoBlmLunas.setSelected(true);
        rdoBlmLunas.setText("Belum Lunas");
        rdoBlmLunas.setName("rdoBlmLunas"); // NOI18N

        buttonGroup1.add(rdoLunas);
        rdoLunas.setText("Lunas");
        rdoLunas.setName("rdoLunas"); // NOI18N

        buttonGroup1.add(rdoAll);
        rdoAll.setText("All");
        rdoAll.setName("rdoAll"); // NOI18N

        btnFilter.setText("Filter");
        btnFilter.setAutoscrolls(true);
        btnFilter.setName("btnFilter"); // NOI18N
        btnFilter.setPreferredSize(new java.awt.Dimension(100, 37));
        btnFilter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFilterActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(32, 32, 32)
                                .addComponent(dtTgl1, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addGap(18, 18, 18)
                                .addComponent(cboCustomer, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(dtTgl2, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(rdoJthTempo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(rdoBlmLunas)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(rdoLunas)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(rdoAll)))
                .addContainerGap(393, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(btnFilter, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(rdoJthTempo)
                            .addComponent(rdoBlmLunas)
                            .addComponent(rdoLunas)
                            .addComponent(rdoAll))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(dtTgl1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2)
                            .addComponent(dtTgl2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cboCustomer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addContainerGap())
        );

        jPanel2.setAutoscrolls(true);
        jPanel2.setName("jPanel2"); // NOI18N

        jTabbedPane1.setName("jTabbedPane1"); // NOI18N

        jScrollPane1.setAutoscrolls(true);
        jScrollPane1.setName("jScrollPane1"); // NOI18N

        tbPiutang.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null}
            },
            new String [] {
                "No Faktur", "Tanggal", "Customer", "Syarat", "Jth Tempo", "Jumlah", "No Ref", "Ket"
            }
        ));
        tbPiutang.setCellSelectionEnabled(true);
        tbPiutang.setName("tbPiutang"); // NOI18N
        jScrollPane1.setViewportView(tbPiutang);
        tbPiutang.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tbPiutang.getColumnModel().getColumn(0).setPreferredWidth(50);
        tbPiutang.getColumnModel().getColumn(1).setPreferredWidth(30);
        tbPiutang.getColumnModel().getColumn(4).setPreferredWidth(50);
        tbPiutang.getColumnModel().getColumn(5).setPreferredWidth(40);
        tbPiutang.getColumnModel().getColumn(6).setPreferredWidth(40);
        tbPiutang.getColumnModel().getColumn(7).setPreferredWidth(30);

        jTabbedPane1.addTab("Piutang", jScrollPane1);

        jScrollPane2.setAutoscrolls(true);
        jScrollPane2.setName("jScrollPane2"); // NOI18N

        tbBukuPiutang.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null, null}
            },
            new String [] {
                "No", "Kode", "Nama Akun", "Deskripsi", "Tanggal", "Debet", "Kredit", "No Faktur", "Ket"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                true, true, true, true, true, true, true, false, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tbBukuPiutang.setName("tbBukuPiutang"); // NOI18N
        jScrollPane2.setViewportView(tbBukuPiutang);
        tbBukuPiutang.getColumnModel().getColumn(0).setPreferredWidth(50);
        tbBukuPiutang.getColumnModel().getColumn(1).setPreferredWidth(30);
        tbBukuPiutang.getColumnModel().getColumn(4).setPreferredWidth(50);
        tbBukuPiutang.getColumnModel().getColumn(5).setPreferredWidth(40);
        tbBukuPiutang.getColumnModel().getColumn(6).setPreferredWidth(40);
        tbBukuPiutang.getColumnModel().getColumn(7).setPreferredWidth(60);
        tbBukuPiutang.getColumnModel().getColumn(8).setPreferredWidth(30);

        jTabbedPane1.addTab("Buku Piutang", jScrollPane2);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 998, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 379, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jToolBar1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 998, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(16, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnFilterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFilterActionPerformed
        // TODO add your handling code here:
        if (rdoJthTempo.isSelected()){
            piutangModels = MainService.getPenjualanService().getPiutangsJthTempoBlmLunas();
        }else if(rdoBlmLunas.isSelected()){
            piutangModels = MainService.getPenjualanService().getPiutangsBlmLunas();
        }else if(rdoLunas.isSelected()){
            piutangModels = MainService.getPenjualanService().getPiutangsLunas();
        }else{
            piutangModels = MainService.getPenjualanService().getPiutangs();
        }
        refreshTablePiutang();
    }//GEN-LAST:event_btnFilterActionPerformed

    private void btnAddPiutangActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddPiutangActionPerformed
        // TODO add your handling code here:
        new LookUpEntryPiutang(null, true).setVisible(true);
        piutangModels = MainService.getPenjualanService().getPiutangs();
        refreshTablePiutang();
    }//GEN-LAST:event_btnAddPiutangActionPerformed

    private void btnPenerimaanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPenerimaanActionPerformed
        // TODO add your handling code here:
        if (piutangModel == null){
            JOptionPane.showMessageDialog(null, "Pilih Piutang terlebih dahulu ....");
        }else{
            BukuPiutangModel bp = new LookUpBayarPiutang(null, true, piutangModel).getBukuPiutang();
            if (bp != null)
                bukuPiutangModels.add(bp);
        }
        piutangModels = MainService.getPenjualanService().getPiutangs();
        refreshTablePiutang();
        
        refreshTableBukuPiutang();
    }//GEN-LAST:event_btnPenerimaanActionPerformed

    private void cboCustomerItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboCustomerItemStateChanged
        // TODO add your handling code here:
        try{
            CustomerModel c = (CustomerModel) cboCustomer.getSelectedItem();
            if (rdoJthTempo.isSelected()){
                piutangModels = MainService.getPenjualanService().getPiutangsByCustomerBlmLns(c);
            }else{
                piutangModels = MainService.getPenjualanService().getPiutangsByCustomer(c);
            }
            refreshTablePiutang();
        }catch(Exception e){
           
        }
    }//GEN-LAST:event_cboCustomerItemStateChanged

    private void refreshTablePiutang(){
        tbPiutang.setAutoCreateColumnsFromModel(false);
        tbPiutang.setModel(new PiutangTableModel(piutangModels));
    }

    private void refreshTableBukuPiutang(){
        tbBukuPiutang.setAutoCreateColumnsFromModel(false);
        tbBukuPiutang.setModel(new BukuPiutangTableModel(bukuPiutangModels));
    }

    private class PiutangTableModel extends AbstractTableModel{
        private List<PiutangModel> piutangModels;

        public PiutangTableModel(List<PiutangModel> piutangModels) {
            this.piutangModels = piutangModels;
        }

        @Override
        public int getRowCount() {
            return piutangModels.size();
        }

        @Override
        public int getColumnCount() {
            return 8;
        }

        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
                PiutangModel s = piutangModels.get(rowIndex);
                if (columnIndex == 1){
                    if (s.getTanggal() != null)
                        return new SimpleDateFormat("dd/MM/yyyy").format(s.getTanggal());
                }else if (columnIndex == 2){
                    if (s.getCustomer().getNama() != null)
                        return s.getCustomer().getNama();
                }else if (columnIndex == 3){
                    if (s.getSyaratBayar() != null)
                        return s.getSyaratBayar();
                }else if (columnIndex == 0){
                    if (s.getNoFaktur() != null)
                        return s.getNoFaktur();
                }else if (columnIndex == 4){
                    if (s.getTanggalJatuhTempo() != null)
                        return new SimpleDateFormat("dd/MM/yyyy").format(s.getTanggalJatuhTempo());
                }else if (columnIndex == 5){
                    if (s.getJumlah() != null)
                        return s.getJumlah();
                }else if (columnIndex == 6){
                    if (s.getNoReferensi() != null)
                        return s.getNoReferensi();
                }else if (columnIndex == 7){
                    if (s.getKeterangan() != null)
                        return s.getKeterangan();
                }
                return "";
        }

        @Override
        public Class<?> getColumnClass(int columnIndex) {
            if(columnIndex == 5){
                return BigDecimal.class;
            }
            return String.class;
        }

        @Override
        public boolean isCellEditable(int rowIndex, int columnIndex) {           
            return false;
        }
    }

    private class PiutangSelectionListener implements ListSelectionListener{

        public void valueChanged(ListSelectionEvent e) {
            if(tbPiutang.getSelectedRow()>=0){
                bukuPiutangModels = piutangModels.get(tbPiutang.getSelectedRow()).getBukuPiutangModels();
                piutangModel = piutangModels.get(tbPiutang.getSelectedRow());
                refreshTableBukuPiutang();
            }
        }

    }

    private class BukuPiutangTableModel extends AbstractTableModel{
        private List<BukuPiutangModel> bukuPiutangModels;

        public BukuPiutangTableModel(List<BukuPiutangModel> bukuPiutangModels) {
            this.bukuPiutangModels = bukuPiutangModels;
        }

        @Override
        public int getRowCount() {
            return bukuPiutangModels.size();
        }

        @Override
        public int getColumnCount() {
            return 9;
        }

        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
                BukuPiutangModel s = bukuPiutangModels.get(rowIndex);
                if (columnIndex == 1){
                    if (s.getAkunMaster().getKodeAkun() != null)
                        return s.getAkunMaster().getKodeAkun();
                }else if (columnIndex == 2){
                    if (s.getAkunMaster().getNama() != null)
                        return s.getAkunMaster().getNama();
                }else if (columnIndex == 3){
                    if (s.getDeskripsi() != null)
                        return s.getDeskripsi();
                }else if (columnIndex == 0){
                        return rowIndex + 1;
                }else if (columnIndex == 4){
                    if (s.getTanggal() != null)
                        return new SimpleDateFormat("dd/MM/yyyy").format(s.getTanggal());
                }else if (columnIndex == 5){
                    if (s.getDebet() != null)
                        return s.getDebet();
                }else if (columnIndex == 6){
                    if (s.getKredit() != null)
                        return s.getKredit();
                }else if (columnIndex == 7){
                    if (s.getNoFaktur() != null)
                        return s.getNoFaktur();
                }else if (columnIndex == 8){
                    if (s.getKeterangan() != null)
                        return s.getKeterangan();
                }
                return "";
        }

        @Override
        public Class<?> getColumnClass(int columnIndex) {
            if(columnIndex == 5 || columnIndex == 6){
                return BigDecimal.class;
            }
            return String.class;
        }

        @Override
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return false;
        }
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAddPiutang;
    private javax.swing.JButton btnFilter;
    private javax.swing.JButton btnPenerimaan;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JComboBox cboCustomer;
    private com.toedter.calendar.JDateChooser dtTgl1;
    private com.toedter.calendar.JDateChooser dtTgl2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JRadioButton rdoAll;
    private javax.swing.JRadioButton rdoBlmLunas;
    private javax.swing.JRadioButton rdoJthTempo;
    private javax.swing.JRadioButton rdoLunas;
    private javax.swing.JTable tbBukuPiutang;
    private javax.swing.JTable tbPiutang;
    // End of variables declaration//GEN-END:variables

}
